Grokking Scalable Systems for Interviews
Rate this course
Ask Author
Contribute
Back to course home

4% completed

Vote For New Content
Introduction
Course Overview
Who This Course Is for
Caching
What Is Negative Caching and When Should You Cache 404 or Empty Results?
What Is the Difference Between Soft TTL and Hard TTL, and Why Does It Matter?
How Can a Bloom Filter Reduce Cache or Database Load?
What Is Distributed Locking for Cache Rebuilds, and How Does It Prevent Cache Stampedes?
Load Balancing
What Are Sticky Sessions (Session Affinity) and When Should I Avoid Them?
What Is the Difference between Liveness Checks and Readiness Checks in Load Balancers?
What is Global Server Load Balancing (GSLB) and How GeoDNS and Anycast Work?
API Basics
What are the Main API Pagination Strategies (offset, cursor, keyset), and When Should I Use Each?
What are HTTP Conditional Requests (ETag, If‑None‑Match, Last‑Modified) and How They Reduce Load?
What Is the Difference between Rate Limiting and Throttling and Quotas?
What Are Idempotency Keys and How to Implement Them Safely for Payments
Databases
What are SQL Isolation Levels (Read Committed, Repeatable Read, Serializable), and What Anomalies Do They Prevent?
What Is a Write‑Ahead Log (WAL), and How Does It Ensure Durability?
What Is the Difference Between Synchronous and Asynchronous Replication, and When Should I Use Read Replicas?
What Is MVCC (Multi‑Version Concurrency Control), and How Does It Enable Concurrent Reads and Writes?
What Are Safe Patterns for Online Schema Changes vs. Offline Migrations?
Scalability
What is Little’s Law and How to Use It for Quick Capacity Estimates in System Design
How Can I do Back-of-the-Envelope Sizing for QPS, Bandwidth, Storage, and Peak vs. Average Load?
What are Cold Starts and Warm Starts, and Why Do They Matter for Performance?
Sharding and Partitioning
How Do I Choose a Good Shard Key and Avoid Hotspots (Bucketing and Key Randomization)?
What Are Range Sharding, Directory‑Based Sharding, and Geo‑Sharding, and What Are the Common Use Cases?
What Is the Difference Between Rendezvous Hashing and Consistent Hashing, and When Should I Use Each?
Messaging and Streaming
What Do At‑most‑once, At‑least‑once, And Exactly‑once Delivery Semantics Mean?
What Are Idempotent Producers And Consumers, And How Do De‑duplication Keys Work?
What Is Message Ordering, How Do Partition Keys Affect It, And When Can Ordering Break?
What Are Windowing And Watermarking In Streaming Systems, In Simple Terms?
Consistency and Replication
What Is Quorum (N, R, W), And Why Does R + W > N Give Strongly Consistent Reads?
What Are Common Conflict Resolution Strategies (Last‑write‑wins, Vector Clocks, Logical Clocks)?
What Are Read Repair, Hinted Handoff, And Anti‑entropy (Merkle Trees) In Eventually Consistent Systems?
Observability
What Is The Difference Between SLI, SLO, And SLA, And Can You Give Simple Examples?
What Is Opentelemetry, And How Do Traces, Spans, Metrics, And Logs Fit Together?
What Is An Error Budget, And How Should It Guide Release Decisions?
Security
What Are The Trade‑offs Between Server‑stored Sessions And JWTs for Authentication?
What Is The Difference Between TLS And MTLS, And When Is MTLS Appropriate For Service‑to‑service Auth?
What Is Secrets Management, And How Do Environment Variables, KMS, And Vault Compare?
What Is A Replay Attack, And How Is It Different from Idempotency Issues?
Networking
What Are The Differences Between TCP, UDP, And QUIC, And When Should I Use Each?
What Is The Difference Between A Forward Proxy, A Reverse Proxy, And NAT?
What Changed From HTTP/1.1 To HTTP/2 To HTTP/3, And What Are Head‑of‑line Blocking And Multiplexing?
Storage
What Is the Difference Between Content‑Addressable Storage and Location‑Based Addressing?
What Are Checksums and Etags, and How Do MD5/SHA Compare to CRC for Integrity?
What Are Hot, Warm, Cold, and Archive Storage Tiers, and When Should I Use Each?
Design Patterns
What Is the Outbox Pattern, and How Does Change Data Capture (CDC) Work at a High Level?
What Is CQRS (Command Query Responsibility Segregation), and When Should I Consider It?
What Are the Differences Between a Circuit Breaker, Retry With Backoff, and Rate Limiting?
Reliability and Operations
What Are RPO and RTO, and How Do They Differ in Disaster Recovery Planning?
What Is the Difference Between Active‑Active and Active‑Passive Architectures?
What Is Graceful Degradation, and How Do Feature Flags Help Availability?
Time and IDs
What Are the Differences Between UUID, ULID, KSUID, and Snowflake IDs, and How Do I Choose?
How Do Snowflake‑Style IDs Work (Timestamp, Worker, Sequence), and What Problems Do They Solve?
What Is the Difference Between Wall‑Clock Time and Monotonic Time, and Why Is Clock Skew Hard?
Final Words
Key Takeaways
What To Learn Next
What Is the Difference Between Wall‑Clock Time and Monotonic Time, and Why Is Clock Skew Hard?

Wall-clock time (system “real time”) is the machine’s current date/time of day, which can jump forward or backward when the clock is adjusted (by NTP sync, daylight savings, manual change, etc.), while monotonic time is a steadily increasing timer (often since boot) that never goes backwards.

Clock skew is the drift or offset between different clocks (for example, on different servers), which is hard to eliminate because each clock runs at a slightly different rate and network sync protocols can’t perfectly align them.

Wall-Clock Time (Real Time)

Wall-clock time (also called system time or real-time clock) represents actual calendar time.

It answers questions like “what time of day is it?” and is used for timestamps, scheduling tasks, and logging.

Because it reflects human time (UTC/local time), it can be adjusted by external events: for instance, a time-sync service (NTP) might set your clock forward a few seconds, or a user could manually change the system time.

Such adjustments mean the wall-clock can jump or even move backwards (e.g. after a backward NTP update).

  • Example: If your laptop sleeps and then resumes, the system clock may jump ahead by the sleep duration, but any timers based on wall-clock will reflect that jump.

  • Consequence: Using wall-clock to measure elapsed time is unreliable in such cases, since the elapsed calculation might become negative or incorrect if the clock was changed mid-measurement.

In practice, wall-clock is great for events tied to real time (e.g. “run this job at 6:00 PM”), but programs must handle the fact that the clock can be reset, adjusted for leap seconds, or synced with internet time.

Learn about Vector Clocks.

Monotonic Time

Monotonic time is a special clock that only measures elapsed time. It typically counts continuously from a fixed point (such as system startup) and always increases at a steady rate.

Because it isn’t linked to the real-world date, it cannot be changed or set by the user or NTP. It will never jump backwards or forward.

This makes it ideal for measuring durations, timeouts, or intervals.

  • Example: To time how long a function takes, you’d use monotonic time for both start and end. Even if the system clock changes during execution, the monotonic clock simply kept ticking, so the elapsed value is correct. In fact, one article advises using monotonic timers in benchmarks to “guarantee that our seconds are moving…forward”.

  • Use case: Monotonic clocks are used under the hood in many programming languages. For example, Linux’s clock_gettime(CLOCK_MONOTONIC) and Python’s time.monotonic() provide this behavior. Unlike the wall-clock, you can’t interpret monotonic time as a date, it’s just a high-resolution counter.

Key Differences

Unlike wall-clock time, monotonic time is immune to manual or automatic adjustments.

Wall-clock can be synchronized across machines (so 6 PM here means 6 PM there), whereas each machine’s monotonic clock is independent (each starts from its own zero).

Crucially, when measuring elapsed time, monotonic timers guarantee a non-negative interval, while wall-clock measurements might even go negative if the clock is set back.

  • Use monotonic time for measuring durations, timeouts, or intervals (e.g. how long a query took).

  • Use wall-clock time for actual date/time stamps, scheduling, or logging real-world events.

Difference Between Wall‑Clock Time and Monotonic Time
Difference Between Wall‑Clock Time and Monotonic Time

Clock Skew and Synchronization

Clock skew refers to the differences or drift between clocks, typically in a distributed system with multiple machines.

Even if all clocks are initially synced, each hardware clock “ticks” at a slightly different rate, so over time their readings diverge.

The difference in rate is called skew, and the difference in current time is called offset.

For example, imagine two clocks that start in sync.

If one runs just a tiny bit faster, after a while it will show a later time than the other; that growing gap is clock skew.

Why Clock Skew is Hard

Eliminating clock skew is challenging because there is no perfect global clock and physical limitations introduce error.

Some key reasons:

  • Hardware Drift: Every physical clock (crystal oscillator) has slight manufacturing and environmental variations. Temperature changes or aging cause clocks to tick faster or slower. You can’t guarantee two clocks run at the exact same rate. Even a tiny drift accumulates large offsets quickly.

  • Network Delays: Synchronizing clocks (via protocols like NTP) requires exchanging messages. Variability in network latency (jitter) means you never know the exact one-way delay, so any correction has some uncertainty.

  • NTP Limits: NTP can typically sync system clocks to within a few milliseconds on a local network. That’s fine for most purposes, but not adequate if you need microsecond or nanosecond precision (e.g. some financial systems or real-time sensors). Even NTP itself only gradually slews the clock (it won’t suddenly jump it more than 0.05% without causing errors).

  • Resets and Adjustments: As with wall-clock jumps, synchronization can overshoot or be delayed. If a clock is adjusted backwards (for example, an NTP step or leap second), logs and timeouts relying on that clock may behave incorrectly. Some systems avoid stepping the clock backwards (slewing slowly instead) precisely because backward jumps break assumptions.

Because of these factors, complete elimination of skew is impossible.

In distributed systems, this makes tasks like globally ordering events by timestamp difficult.

For example, if Server A’s clock is a second ahead of Server B’s, an event logged at 12:00:01 on A might actually have happened after an event at 12:00:02 on B, causing confusion.

In practice, systems either tolerate some skew (e.g. by including clock uncertainty in algorithms) or use logical clocks (Lamport timestamps, vector clocks) that avoid relying on synchronized physical time.

Summary

Wall-clock (real) time and monotonic time serve different needs.

Use monotonic timers for measuring elapsed time to avoid jump-induced errors.

Clock skew is the inevitable mismatch between clocks. It is hard because every clock drifts and network sync is imperfect.

Understanding the difference and the limits of synchronization helps developers choose the right clock and design robust, time-sensitive code.

How Do Snowflake‑Style IDs Work (Timestamp, Worker, Sequence), and What Problems Do They Solve?
Final Words
Mark as Completed

On this page

Wall-Clock Time (Real Time)

Monotonic Time

Key Differences

Clock Skew and Synchronization

Why Clock Skew is Hard

Summary